package com.nmm.demo.config;

import com.nmm.demo.service.McpBusinessService;
import jakarta.annotation.Resource;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.ai.tool.ToolCallbackProvider;
import org.springframework.ai.tool.method.MethodToolCallbackProvider;
import org.springframework.ai.transformer.splitter.TokenTextSplitter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author niemingming
 * @Date 2025/6/12
 */
@Configuration
public class AiDemoConfig {

  @Resource
  private OllamaChatModel ollamaChatModel;

  @Bean(name = "ollamaChatClient")
  public ChatClient ollamaChatClient() {
    return ChatClient.builder(ollamaChatModel)
        .defaultSystem("你好，我是检索机器人").build();
  }
  @Resource
  private McpBusinessService mcpBusinessService;

  @Bean(name = "businessChatClient")
  public ChatClient businessChatClient() {
//    MethodToolCallbackProvider.builder().toolObjects(mcpBusinessService).build().getToolCallbacks()
    return ChatClient.builder(ollamaChatModel).defaultSystem("""
        你是一个业务才能机器人，你可以提供一下服务：
        根据用户工号或者姓名，模糊查询用户信息。
        根据订单编号，模糊查询订单信息
        """).defaultTools(mcpBusinessService).build();
  }

  // 手动设置token分词大小
  @Bean
  public TokenTextSplitter tokenTextSplitter() {
    TokenTextSplitter tokenTextSplitter = new TokenTextSplitter(64, 32, 32, 128, true);
    return tokenTextSplitter;
  }

}
